home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / c / SetmouseSource.lha / SetMouse / SetMouse.c < prev    next >
C/C++ Source or Header  |  1995-12-06  |  4KB  |  146 lines

  1. /*
  2.  *    File:                    SetMouse.c
  3.  *    Description:    Position the mouse at any coordinates
  4.  *
  5.  *    (C) 1994,1995, Ketil Hunn
  6.  *
  7.  */
  8.  
  9. /*** PRIVATE INCLUDES ****************************************************************/
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <exec/libraries.h>
  13. #include <devices/input.h>
  14. #include <devices/inputevent.h>
  15. #include <intuition/screens.h>
  16.  
  17. #include <dos/dos.h>
  18. #include <dos/dostags.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21.  
  22. #include <clib/exec_protos.h>
  23. #include <clib/intuition_protos.h>
  24.  
  25.  
  26. /*** DEFINES *************************************************************************/
  27. #define TEMPLATE "XPOS=NUMBER/A/N,YPOS=NUMBER/A/N,LEFTBUTTON/S,MIDDLEBUTTON/S,RIGHTBUTTON/S,DOUBLECLICK/S"
  28. #define XPOS                     0
  29. #define YPOS                     1
  30. #define LEFTBUTTON         2
  31. #define MIDDLEBUTTON    3
  32. #define RIGHTBUTTON     4
  33. #define DOUBLECLICK     5
  34.  
  35. #define    ARGUMENTS            6
  36.  
  37. /*** GLOBALS *************************************************************************/
  38. char const *version="\0$VER: SetMouse 2.0 (07.12.95)\©1995 Ketil Hunn";
  39.  
  40. extern struct Library *SysBase;
  41. struct IntuitionBase *IntuitionBase;
  42.  
  43. /*** FUNCTIONS ***********************************************************************/
  44. void SetMouse(struct Screen *screen, WORD x, WORD y, UWORD button)
  45. {
  46.     struct IOStdReq                *InputIO;
  47.     struct MsgPort                *InputMP;
  48.     struct InputEvent            *FakeEvent;
  49.     struct IEPointerPixel    *NeoPix;
  50.  
  51.     if(InputMP=CreateMsgPort())
  52.     {
  53.         if(FakeEvent=AllocVec(sizeof(struct InputEvent), MEMF_PUBLIC))
  54.         {
  55.             if(NeoPix=AllocVec(sizeof(struct IEPointerPixel), MEMF_PUBLIC))
  56.             {
  57.                 if(InputIO=CreateIORequest(InputMP, sizeof(struct IOStdReq)))
  58.                 {
  59.                     if(!OpenDevice("input.device", NULL, (struct IORequest *)InputIO, NULL))
  60.                     {
  61.                         NeoPix->iepp_Screen                    =(struct Screen *)screen;
  62.                         NeoPix->iepp_Position.X            =x;
  63.                         NeoPix->iepp_Position.Y            =y;
  64.  
  65.                         FakeEvent->ie_EventAddress    =(APTR)NeoPix;
  66.                         FakeEvent->ie_NextEvent            =NULL;
  67.                         FakeEvent->ie_Class                    =IECLASS_NEWPOINTERPOS;
  68.                         FakeEvent->ie_SubClass            =IESUBCLASS_PIXEL;
  69.                         FakeEvent->ie_Code                    =0;
  70.                         FakeEvent->ie_Qualifier         =NULL;
  71.  
  72.                         InputIO->io_Data                        =(APTR)FakeEvent;
  73.                         InputIO->io_Length                    =sizeof(struct InputEvent);
  74.                         InputIO->io_Command                    =IND_WRITEEVENT;
  75.                         DoIO((struct IORequest *)InputIO);
  76.  
  77.                         if(button!=IECODE_NOBUTTON)
  78.                         {
  79.                             /* BUTTON DOWN */
  80.                             FakeEvent->ie_EventAddress    =NULL;
  81.                             FakeEvent->ie_Class                    =IECLASS_RAWMOUSE;
  82.                             FakeEvent->ie_Code                    =button;
  83.                             DoIO((struct IORequest *)InputIO);
  84.  
  85.                             /* BUTTON UP */
  86.                             FakeEvent->ie_Code                    =button|IECODE_UP_PREFIX;
  87.                             DoIO((struct IORequest *)InputIO);
  88.                         }
  89.                         CloseDevice((struct IORequest *)InputIO);
  90.                     }
  91.                     DeleteIORequest(InputIO);
  92.                 }
  93.                 FreeVec(NeoPix);
  94.             }
  95.             FreeVec(FakeEvent);
  96.         }
  97.         DeleteMsgPort(InputMP);
  98.     }
  99. }
  100.  
  101. void __main(void)
  102. {
  103.     if(SysBase->lib_Version>35)
  104.     {
  105.         struct RDArgs    *args;
  106.         register LONG    arg[ARGUMENTS]={0L, 0L, 0L, 0L, 0L, 0L};
  107.  
  108.         if(args=ReadArgs(TEMPLATE, arg, NULL))
  109.         {
  110.             struct Screen *screen;
  111.  
  112.             if(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library", 36L))
  113.             {
  114.                 if(screen=(struct Screen *)LockPubScreen(NULL))
  115.                 {
  116.                     register WORD     x=(WORD)*((LONG *)arg[XPOS]),
  117.                                                     y=(WORD)*((LONG *)arg[YPOS]);
  118.                     register UWORD    button=0;
  119.                     register UBYTE    clicks=1;
  120.  
  121.                     if(arg[LEFTBUTTON])
  122.                         button=IECODE_LBUTTON;
  123.                     if(arg[MIDDLEBUTTON])
  124.                         button|=IECODE_MBUTTON;
  125.                     if(arg[RIGHTBUTTON])
  126.                         button|=IECODE_RBUTTON;
  127.                     if(button==0)
  128.                         button=IECODE_NOBUTTON;
  129.  
  130.                     if(arg[DOUBLECLICK])
  131.                         clicks=2;
  132.  
  133.                     while(clicks--)
  134.                         SetMouse(screen,    (x==-1 ? screen->Width/2    : x),
  135.                                                             (y==-1 ? screen->Height/2    : y),
  136.                                                             button);
  137.  
  138.                     UnlockPubScreen(NULL, screen);
  139.                 }
  140.                 CloseLibrary((struct Library *)IntuitionBase);
  141.             }
  142.             FreeArgs(args);
  143.         }
  144.     }
  145. }
  146.